<template>
  <div id="online">
    <div style="margin:auto;width:100%;" v-if="flag">
      <div id="logo" style="" ></div>
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="right" label-width="60px" class="demo-ruleForm">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="ruleForm.name" />
        </el-form-item>
        <el-form-item label="手机" prop="phone">
          <el-input v-model="ruleForm.phone" />
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="ruleForm.school" />
        </el-form-item>
      </el-form>
      <el-button type="primary" style="width:80%;margin:0 auto;display: block" @click="onSubmit()">提交</el-button>
    </div>
    <el-image
      v-if="!flag"
      style="width: 100%; height: 100%"
      :src="qunurl"
      fit="contain"
    />
  </div>
</template>

<script>
export default {
  name: '',
  data() {
    const checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入手机号'))
      } else {
        const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
        if (reg.test(value)) {
          callback()
        } else {
          return callback(new Error('请输入正确的手机号'))
        }
      }
    }
    return {
      imgurl: this.imgurl + 'group1/M00/00/00/rBUAAl5RDWeASWxzAALAMh1sF-Y768.jpg?' + new Date().getTime(),
      qunurl: this.imgurl + 'group1/M00/00/00/rBUAAl5TSY6AVX7HAAK0iDqVONY495.png?' + new Date().getTime(),
      flag: true,
      ruleForm: {
        name: '',
        phone: '',
        school: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 1, max: 5, message: '长度在 1 到 5 个字符', trigger: 'blur' }
        ],
        phone: [
          { validator: checkPhone, message: '请输入正确的手机号', trigger: 'blur' },
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
        school: [
          { required: true, message: '请输入学校', trigger: 'blur' },
          { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    onSubmit() {
      this.post('/pub-student/save', 'ruleForm', result => {
        if (result.code === 1) {
          this.flag = false
        }
      }, this.ruleForm)
    }
  }
}
</script>
<style>
  #online {
    display: flex;
    overflow-y: auto;
    height:100%;
  }
  #online #logo {
    width:234px;
    height:44px;
    margin:0 auto;
    background: url(../../assets/logo.svg) no-repeat center;
  }
  #online #el-drawer__title{
    display:none
  }
  .myfm{
    opacity: 0.94;
  }
</style>
<style scoped>
  .demo-ruleForm{
    padding-right:30px;
  }
</style>
